package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import com.moyq5.mvc.maker.test.bean.ChannelIdUserType;
import com.moyq5.mvc.maker.test.bean.enums.ChannelId;
import com.moyq5.mvc.maker.test.bean.enums.ChannelStatus;
import com.moyq5.mvc.maker.test.bean.enums.SysTradeType;

/**
 * 渠道信息
 * @author Moyq5
 * @date 2017年12月9日
 */
@TypeDef(name = "channelId", typeClass = ChannelIdUserType.class)
@Entity
@Table(name = "tra_channel")
@DynamicUpdate
public class TraChannel implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 渠道ID
	 */
	@Id
    @Column(name = "channel_id")
	@Type(type = "channelId")
	private ChannelId channelId;
	/**
	 * 渠道名称
	 */
	@Column(name = "name", length = 60, nullable = false)
	private String name;
	/**
	 * 虚拟账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "virtual_account_id", nullable = false)
	private VirtualAccount virtualAccount;
	/**
	 * 计费方式
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "rounding_mode", nullable = false)
	private RoundingMode roundingMode;
	/**
	 * 状态
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status", nullable = false)
	private ChannelStatus status;
	/**
	 * 渠道描述
	 */
    @Column(name = "remark", length = 300)
	private String remark;
    /**
	 * 交易类型
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "trade_type", columnDefinition="int(1) not null default '0'")
	private SysTradeType tradeType;
	/**
	 * 交易限制
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "confine_id", nullable = false)
	private TraConfine confine;
	/**
	 * 提现单笔费率，如：0.0049
	 */
	@Column(name = "remit_rate", columnDefinition = "decimal(5,4) not null default '0.0000'")
	private BigDecimal remitRate;
	/**
	 * 提现单笔提现费（元）
	 */
	@Column(name = "remit_fee", columnDefinition = "decimal(10,2) not null default '2.00'")
	private BigDecimal remitFee;
    /**
     * 支付配置信息
     */
    @OneToOne(mappedBy="channel", optional = true)
    private TraChannelInfo channelInfo;
    /**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}
	
	public ChannelId getChannelId() {
		return channelId;
	}
	public void setChannelId(ChannelId channelId) {
		this.channelId = channelId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public VirtualAccount getVirtualAccount() {
		return virtualAccount;
	}
	public void setVirtualAccount(VirtualAccount virtualAccount) {
		this.virtualAccount = virtualAccount;
	}
	public RoundingMode getRoundingMode() {
		return roundingMode;
	}
	public void setRoundingMode(RoundingMode roundingMode) {
		this.roundingMode = roundingMode;
	}
	public ChannelStatus getStatus() {
		return status;
	}
	public void setStatus(ChannelStatus status) {
		this.status = status;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public TraChannelInfo getChannelInfo() {
		return channelInfo;
	}
	public void setChannelInfo(TraChannelInfo channelInfo) {
		this.channelInfo = channelInfo;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public BigDecimal getRemitRate() {
		return remitRate;
	}

	public void setRemitRate(BigDecimal remitRate) {
		this.remitRate = remitRate;
	}

	public BigDecimal getRemitFee() {
		return remitFee;
	}

	public void setRemitFee(BigDecimal remitFee) {
		this.remitFee = remitFee;
	}

	public SysTradeType getTradeType() {
		return tradeType;
	}

	public void setTradeType(SysTradeType tradeType) {
		this.tradeType = tradeType;
	}

	public TraConfine getConfine() {
		return confine;
	}

	public void setConfine(TraConfine confine) {
		this.confine = confine;
	}
	
}
